<template>
  <a-table
    :columns="columns"
    :data-source="tableData"
    class="checkTable"
    :pagination="false"
    :scroll="{ x: 1500 }"
  >
    <span slot="isfast" slot-scope="text, record">
      <span style="margin-right: 5px">{{ record.businessType }}</span>
      <span v-if="record.fastInOut == '1'" class="isfast">快</span>
    </span>
    <span slot="action" class="action" slot-scope="text, record">
      <a
        slot="action"
        href="javascript:;"
        @click="submitData(record, 'submit')"
        v-if="['待提交', '审核不通过'].includes(TransferOutKeys)"
        >提交订单</a
      >
      <a-divider
        type="vertical"
        v-if="['待提交', '审核不通过'].includes(TransferOutKeys)"
      />
      <a
        slot="action"
        href="javascript:;"
        @click="eidtRow(record, 'edit')"
        v-if="
          ['待发头程', '待提交', '审核不通过', '待发头程'].includes(
            TransferOutKeys
          )
        "
        >编辑订单</a
      >
      <a-divider
        type="vertical"
        v-if="['待仓库处理', '待提交', '审核不通过'].includes(TransferOutKeys)"
      />
      <a
        slot="action"
        href="javascript:;"
        @click="submitData(record, 'submit')"
        v-if="['异常订单'].includes(TransferOutKeys)"
        >重新提交</a
      >
      <a-divider
        type="vertical"
        v-if="['异常订单'].includes(TransferOutKeys)"
      />
      <a
        style="margin-right: 10px"
        slot="action"
        href="javascript:;"
        @click="eidtRow(record, 'look')"
        v-if="
          ['待审核', '待仓库接收', '已接收', '已入库'].includes(TransferOutKeys)
        "
        >订单详情</a
      >
      <a-divider
        type="vertical"
        v-if="['待发头程'].includes(TransferOutKeys)"
      />
      <a
        slot="action"
        href="javascript:;"
        @click="submitData(record, 'withdraw')"
        v-if="['待审核', '待发头程'].includes(TransferOutKeys)"
        >撤回订单</a
      >
      <!-- <a-divider type="vertical" v-if="
          ['待仓库处理'].includes(TransferOutKeys)
        "/> -->
      <a-popconfirm
        title="确定删除该条数据吗?"
        ok-text="确定"
        cancel-text="取消"
        @confirm="deleteRow(record)"
        v-if="['待提交', '审核不通过'].includes(TransferOutKeys)"
      >
        <a href="javascript:;">删除订单</a>
      </a-popconfirm>
    </span>
  </a-table>
</template>

<script>
import {
  TransferOut_del,
  TransferOut_submit,
  TransferOut_recallt,
} from "@/apis/clientSide/OrderManage/TransferIn";
export default {
  props: [
    "tableData",
    "TransferOutKeys",
    "getTransferInTableList",
    "getStateCount",
    "isState",
  ],
  data() {
    return {
      SKUTablieData: [],
    };
  },
  methods: {
    //编辑每一行
    eidtRow(rowData, flag) {
      setTimeout(() => {
        this.$bus.$emit(
          "TransferInRowData",
          rowData,
          flag,
          this.TransferOutKeys
        );
      }, 50);
    },
    //删除每一行
    async deleteRow(record) {
      let { code } = await TransferOut_del(
        record.transferWarehousingApplyId,
        record.revision
      );
      if (code === "10000") {
        this.getTransferInTableList();
        this.getStateCount(0);
        this.getStateCount(1);
        this.getStateCount(2);
        this.getStateCount(3);
        this.getStateCount(4);
        this.getStateCount(5);
      }
    },
    submitData(record, flag) {
      let _this = this;
      if (flag == "submit") {
        this.$confirm({
          title: "确认提交该订单吗?",
          cancelText: "取消",
          okText: "确认",
          async onOk() {
            let { code } = await TransferOut_submit(
              record.transferWarehousingApplyId
            );
            if (code == "10000") {
              _this.getTransferInTableList();
              _this.getStateCount(0);
              _this.getStateCount(1);
              _this.getStateCount(2);
              _this.getStateCount(3);
              _this.getStateCount(4);
              _this.getStateCount(5);
            }
          },
        });
      } else if (flag === "withdraw") {
        this.$confirm({
          title: "确认撤回该订单吗?",
          cancelText: "取消",
          okText: "确认",
          onOk() {
            return new Promise((resolve) => {
              setTimeout(async () => {
                let { code } = await TransferOut_recallt(
                  record.transferWarehousingApplyId,
                  record.revision
                );
                if (code === "10000") {
                  resolve();
                }
              }, 1000);
            }).then(() => {
              _this.getTransferInTableList();
              _this.getStateCount(0);
              _this.getStateCount(1);
              _this.getStateCount(2);
              _this.getStateCount(3);
              _this.getStateCount(4);
              _this.getStateCount(5);
            });
          },
        });
      }
    },
  },
  computed: {
    columns() {
      return [
        {
          title: "转运标题",
          dataIndex: "transferTitle",
          align: "center",
          // scopedSlots: { customRender: "selfClassifyName" },
          ellipsis: true,
          width: "15%",
        },
        {
          title: "业务类型",
          dataIndex: "businessType",
          align: "center",
          scopedSlots: { customRender: "isfast" },
          ellipsis: true,
          width: "10%",
        },
        {
          title: "转运入库编号",
          dataIndex: "transferNo",
          align: "center",
          width: "9%",
          ellipsis: true,
        },
        {
          title: "入库仓库",
          dataIndex: "warehouseName",
          // ellipsis: true,
          scopedSlots: { customRender: "warehouseName" },
          align: "center",
          width: "9%",
        },
        {
          title: "创建时间",
          dataIndex: "createTime",
          //   scopedSlots: { customRender: "waybillNo" },
          align: "center",
          width: "11%",
          ellipsis: true,
        },
        {
          title: "状态",
          dataIndex: "auditState",
          scopedSlots: { customRender: "auditState" },
          align: "center",
          width: "9%",
          ellipsis: true,
        },
        {
          title: "备注",
          dataIndex: "remarks",
          //   scopedSlots: { customRender: "remarks" },
          align: "center",
          width: "18%",
          ellipsis: true,
        },
        {
          title: "操作",
          dataIndex: "action",
          scopedSlots: { customRender: "action" },
          align: "center",
          width: 250,
          fixed: "right",
        },
      ];
    },
    columns3() {
      return [
        {
          title: "转运标题",
          dataIndex: "transferTitle",
          align: "center",
          // scopedSlots: { customRender: "selfClassifyName" },
          ellipsis: true,
          width: "10%",
        },
        {
          title: "业务类型",
          dataIndex: "businessType",
          align: "center",
          scopedSlots: { customRender: "isfast" },
          ellipsis: true,
          width: "10%",
        },
        {
          title: "转运入库编号",
          dataIndex: "transferNo",
          align: "center",
          width: "10%",
          ellipsis: true,
        },
        {
          title: "入库仓库",
          dataIndex: "warehousingId",
          // ellipsis: true,
          scopedSlots: { customRender: "warehousingId" },
          align: "center",
          width: "9%",
        },
        {
          title: "创建时间",
          dataIndex: "createTime",
          //   scopedSlots: { customRender: "waybillNo" },
          align: "center",
          width: "11%",
          ellipsis: true,
        },
        {
          title: "状态",
          dataIndex: "logisticsType",
          scopedSlots: { customRender: "logisticsType" },
          align: "center",
          width: "9%",
          ellipsis: true,
        },
        {
          title: "备注",
          dataIndex: "remarks",
          //   scopedSlots: { customRender: "remarks" },
          align: "center",
          width: "15%",
          ellipsis: true,
        },
        {
          title: "操作",
          dataIndex: "action",
          scopedSlots: { customRender: "action" },
          align: "center",
          width: 250,
          fixed: "right",
        },
      ];
    },
  },
};
</script>

<style lang="less" scoped>
.checkTable {
  .isfast {
    display: inline-block;
    background-color: #00bfbf;
    color: #fff;
    height: 24px;
    font-size: 12px;
    width: 24px;
    border: 1px solid #000;
    line-height: 22px;
    border-radius: 12px;
  }
}
.action {
  a {
    border-bottom: 1px solid rgb(41, 41, 224);
    color: rgb(41, 41, 224);
  }
}
</style>
